<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <script src="./js/flexible.js"></script>
  <link rel="stylesheet" type="text/css" href="./css/common.css" />
  <link rel="stylesheet" type="text/css" href="./ad/index.rem.css" />
  <script src="./js/serialLocalStorage.js"></script>

  <style>
    .text-wrapper_2 {
      margin-left: 1rem;
    }

    .text-wrapper_2 span {
      width: 2.32rem;
      height: 0.827rem;
      overflow-wrap: break-word;
      color: rgba(0, 0, 0, 1);
      font-size: 0.586rem;
      font-family: Helvetica, "Microsoft YaHei", Arial, sans-serif;
      font-weight: NaN;
      text-align: left;
      white-space: nowrap;
      line-height: 0.827rem;

    }
  </style>
</head>

<body>
  <div class="page flex-col">
    <div class="group_1 flex-col justify-end">
      <div class="image-wrapper_1 flex-col">
        <!-- <img
            class="image_1"
            referrerpolicy="no-referrer"
            src="./ad/MasterDDSSlicePNG46ef9909dda34d2e8d0703b1282a24b5.png"
          /> -->
        <iframe class="video_box" width="100%" height="100%" src="https://www.youtube.com/embed/vBoP2lyAiXQ?autoplay=1"
          frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; autoplay"
          allowfullscreen>
        </iframe>
      </div>
      <div class="box_1 flex-row">
        <span class="text_1">前艙溫度</span>
        <span class="text_2">64</span>
        <span class="text_3">℃</span>
        <span class="text_4">後艙溫度</span>
        <span class="text_5">64</span>
        <span class="text_6">℃</span>
        <span class="text_7">岩盤溫度</span>
        <span class="text_8">64</span>
        <span class="text_9">℃</span>
        <span class="text_10">剩餘時間</span>
        <div class="text-wrapper_2">
          <span class=" time-min">00</span>
          <span class="">M</span>
          <span class="">&nbsp;:&nbsp;</span>
          <span class=" time-second">00</span>
          <span class="">S</span>
        </div>
        <img id="label_1" class="label_1" referrerpolicy="no-referrer"
          src="./ad/MasterDDSSlicePNG7abbc8b1e4b09975dab0e08f57e5898b.png" />
      </div>
    </div>
  </div>
</body>
<script src="./js/jquery.min.js"></script>
<script>
  $('#label_1').click(function () {
    localStorage.setItem('isReturn', '1')
    window.location.href = './index.html'

  })
  const languageData = {
    "zh-tw": {
      text_1: "前艙溫度",
      text_4: "後艙溫度",
      text_7: "岩盤溫度",
      text_10: "剩餘時間",
   
    },
    "zh-cn": {
      text_1: "前舱温度",
      text_4: "后舱温度",
      text_7: "岩盘温度",
      text_10: "剩余时间",
  
    },
    "en-us": {
      text_1: "Front",
      text_4: "Rear",
      text_7: "Bed",
      text_10: "Timer",
   
    },
    "ja-jp": {
      text_1: "前部",
      text_4: "後部",
      text_7: "ベッド",
      text_10: "残り時間",
  
    },
  };
   //初始化语言格式
    // 从浏览器获取语言类型
    const languageType = serialLocalStorage.get("languageType")
    // 拿到语言包中的对应类型的文字
    const languageObj = languageData[languageType];
    // 拿到对应的数据类,利用返回的数组进行替换语言类型
    debugger
    Object.keys(languageObj).forEach((i)=>{
        // i为对应的文字类,替换文字
        $("." + i).text(languageObj[i])
    })
  //设置广告页面的时间
  setInterval(() => {
    const endTime = localStorage.getItem('time-set')
    if (endTime == "null") return
    const now = new Date().getTime();
    const distance = endTime - now;
    if (distance < 0) {
      localStorage.setItem('time-set', null)
      return;
    }
    // const days = Math.floor(distance / (1000 * 60 * 60 * 24));
    // const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    const seconds = Math.floor((distance % (1000 * 60)) / 1000);
    $('.time-min').text(minutes)
    $('.time-second').text(seconds)
  }, 1000)

  //初始化温度数据
  const temperatureObject = serialLocalStorage.get("temperatureObject");
  $(".text_2").text(temperatureObject["front_cabin_temperature"])
  $(".text_5").text(temperatureObject["rear_cabin_temperature"])
  $(".text_8").text(temperatureObject["rock_temperature"])
  // 需要获取重定向的链接
  const openSrc = "https://mylast.video/u5z0S3y"
  try {
    fetch(openSrc, {
      method: 'GET',
      redirect: 'follow'  // 让 fetch 自动处理重定向
    })
      .then(response => {
        // 将重定向链接返回赋值给finalUrl
        // // 要解析的链接
        const finalUrl = response.url
        const videoId = new URL(finalUrl).searchParams.get("v"); // 提取 YouTube 视频 ID
        // 获取到iframe
        const iframe = document.querySelector(".video_box");
        iframe.src = `https://www.youtube.com/embed/${videoId}?autoplay=1`;
      })
  } catch (error) {
    const finalUrl = "https://www.youtube.com/watch?v=vBoP2lyAiXQ"
    const videoId = new URL(finalUrl).searchParams.get("v"); // 提取 YouTube 视频 ID
    const iframe = document.querySelector(".video_box");
    iframe.src = `https://www.youtube.com/embed/${videoId}?autoplay=1`;
  }
</script>

</html>